﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using FrameWorkSong;
using UnityEngine.UI;

public class SocketExamples : MonoBehaviourSimplify
{
    public InputField input;
    void getInfo(object data)
    {
        Debug.Log(data);
    }
     void Start()
    {
        CreateServerSocket();
       // Delay(2, () => { CreateClientSocket(); });
        Delay(2, CreateClientSocket);
    }
    
    public override void OnBeforeDestroy()
    {
        
    }

    void CreateWebSocket()
    {
        RegisterMsg("getinfo", getInfo);//注册"getinfo"方法
        string ULR = "ws://50.32.15.125:8888/camera/";
        WebSocketsRequest.Instance.CreateWebSockets("getinfo", ULR);
    }
    void RemoveWebSockets()
    {
        WebSocketsRequest.Instance.RemoveSockets("getinfo");
        UnRegisterMsg("getinfo");//注销"getinfo"方法
    }

    void CreateClientSocket()
    {
        RegisterMsg("getinfo", getInfo);//注册"getinfo"方法
        int port = 6001;
        string ip = "192.168.11.106";
        WebSocketsRequest.Instance.CreateSocketClient("getinfo", ip, port);
    }

    void CreateServerSocket()
    {
        RegisterMsg("getinfo", getInfo);//注册"getinfo"方法
        int port = 6001;
        WebSocketsRequest.Instance.CreateSocketServer("getinfo", port);
    }

     public void ClientSocketSend()
    {
        WebSocketsRequest.Instance.SocketClientSend("getinfo", input.text);
    }
    public void CreateWebSocket(string ip, string port)
    {
        RegisterMsg("getinfo", getInfo);
        WebSocketsRequest.Instance.CreateMQTTnet("getinfo", ip, int.Parse(port));
    }
    public void RemoveSockets()
    {
        WebSocketsRequest.Instance.RemoveSockets("getinfo");
    }
}

